package woaini.wind.bot.command.xj;

import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

/**
 * 新疆打卡作业
 *
 * @see XjClockJob
 * @author yefeng {@date 2025-02-19 16:22:37}
 */
@Component
public class XjClockJob {

  public void clockIn() {
    this.clock("in");
  }

  public void clockOut() {
    this.clock("out");
  }

  private void clock(String status) {
    try {
      // 设置Python脚本的路径
      String pythonPath = "/home/xiuyuan/.conda/envs/rpa/bin/python";
      String scriptPath = "/home/xiuyuan/PycharmProjects/wx-rpa/main.py";
      // 创建ProcessBuilder对象
      List<String> command = List.of(pythonPath, scriptPath, status);
      ProcessBuilder processBuilder = new ProcessBuilder(command);
      // 启动子进程
      Process process = processBuilder.start();
      // 读取输出
      BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
      String line;
      while ((line = reader.readLine()) != null) {
        System.out.println(line);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
